package com.sgb.kjwl.viewmodel.home;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.view.entity.MenuEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.fragment.home.LeaseFragment2;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@Deprecated
public class LeaseFragment2Model extends BaseViewModel {
    private HomeRepertory repertory;
    private LeaseFragment2 fragment;

    public LeaseFragment2Model(LeaseFragment2 leaseFragment2, HomeRepertory repertory) {
        this.fragment = leaseFragment2;
        this.repertory = repertory;
    }

    /**
     * 菜单分类
     */
    public void getMenu() {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getHomeLeaseAPI().getMenu().enqueue(new Callback<BaseEntity<List<MenuEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<MenuEntity>>> call, Response<BaseEntity<List<MenuEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (response.body().getData() != null) {
                        fragment.showMenuView(response.body().getData());
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<MenuEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * 推荐机械
     */
    public void getShowMechanics() {
//        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
//        APIManager.getInstance().getHomeLeaseAPI().getShowMechanics(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<ShowMachineEntity>>>() {
//            @Override
//            public void onResponse(Call<BaseEntity<List<ShowMachineEntity>>> call, Response<BaseEntity<List<ShowMachineEntity>>> response) {
//                DialogHelper.dismissProgressDialog();
//                if (response.body() == null) return;
//                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
//                    if (response.body().getData() != null) {
//                        fragment.showOptionView(response.body().getData());
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(Call<BaseEntity<List<ShowMachineEntity>>> call, Throwable t) {
//                DialogHelper.dismissProgressDialog();
//            }
//        });
    }

    /**
     * 推荐设备
     */
    public void getShowDevice() {
//        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
//        APIManager.getInstance().getHomeLeaseAPI().getShowDevice(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<ShowDeviceEntity>>>() {
//            @Override
//            public void onResponse(Call<BaseEntity<List<ShowDeviceEntity>>> call, Response<BaseEntity<List<ShowDeviceEntity>>> response) {
//                DialogHelper.dismissProgressDialog();
//                if (response.body() == null) return;
//                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
//                    if (response.body().getData() != null) {
//                        fragment.showOptionView1(response.body().getData());
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(Call<BaseEntity<List<ShowDeviceEntity>>> call, Throwable t) {
//                DialogHelper.dismissProgressDialog();
//            }
//        });
    }

    /**
     * 推荐车辆
     */
    public void getShowCar() {
//        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
//        APIManager.getInstance().getHomeLeaseAPI().getShowCar(repertory.getAreaCode()).enqueue(new Callback<BaseEntity<List<ShowCarEntity>>>() {
//            @Override
//            public void onResponse(Call<BaseEntity<List<ShowCarEntity>>> call, Response<BaseEntity<List<ShowCarEntity>>> response) {
//                DialogHelper.dismissProgressDialog();
//                if (response.body() == null) return;
//                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
//                    if (response.body().getData() != null) {
//                        fragment.showOptionView2(response.body().getData());
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(Call<BaseEntity<List<ShowCarEntity>>> call, Throwable t) {
//                DialogHelper.dismissProgressDialog();
//            }
//        });
    }

    public void getH5Url(String id){
//        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
//        APIManager.getInstance().getPickAPI().getUrlSetting("vehicleDetails").enqueue(new Callback<BaseEntity<H5ReEntity>>() {
//            @Override
//            public void onResponse(Call<BaseEntity<H5ReEntity>> call, Response<BaseEntity<H5ReEntity>> response) {
//                DialogHelper.dismissProgressDialog();
//                if (response.body() == null || response.body().getState() == null) {
//                    return;
//                }
//
//                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
//                    String url = response.body().getData().getUrl() + "?id=" + id;
//                    WebViewX5HostActivity.start(fragment.getActivity(),url);
//                } else {
//                    MToast.showToast(fragment.getActivity(), response.body().getMsg());
//                }
//            }
//
//            @Override
//            public void onFailure(Call<BaseEntity<H5ReEntity>> call, Throwable t) {
//                DialogHelper.dismissProgressDialog();
//            }
//        });
    }
}
